<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/4/2
 * Time: 9:25
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;

class News extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function list()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        if(!$type = input('get.type'))
            $this->error('缺少参数');
        $page = input('post.page',1);
        $limit = input('post.limit',10);
        $tableName = 'tx_new';
        switch ($type)
        {
            case 1:
                $tableName = 'tx_new';
                break;
            case 2:
                $tableName = 'industry_information';
                break;
            case 3:
                $tableName = 'classroom';
                break;
        }

        $list = Db::name($tableName)->field("*,FROM_UNIXTIME(createtime,'%Y-%m-%d') as time")->order('id','desc')->paginate($limit,false,['page'=>$page]);
        if(!$list)
            $this->error('暂无数据');
        $this->success('',$list);
    }
}